// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dfa.axis.v1_16;

import com.google.api.ads.dfa.lib.client.DfaSession;
import com.google.api.ads.dfa.lib.factory.DfaServices;
import com.google.api.ads.dfa.axis.v1_16.CreativeFieldRemote;
import com.google.api.ads.dfa.axis.v1_16.CreativeFieldValue;
import com.google.api.ads.dfa.axis.v1_16.CreativeFieldValueSaveResult;

/**
 * This example creates a creative field value associated with a given creative
 * field. To get the creative field ID, run GetCreativeFields.java.
 *
 * Credentials and properties in {@code fromFile()} are pulled from the
 * "ads.properties" file. See README for more info.
 *
 * Tags: creativefield.saveCreativeFieldValue
 *
 * @author Joseph DiLallo
 */
public class CreateCreativeFieldValue {

  public static void main(String[] args) throws Exception {
    long creativeFieldId = Long.parseLong("INSERT_CREATIVE_FIELD_ID_HERE");
    String creativeFieldValueName = "INSERT_CREATIVE_FIELD_VALUE_NAME_HERE";

    // Initialize your session.
    DfaSession session = new DfaSession.Builder().fromFile().build();

    // Request the service.
    CreativeFieldRemote service = new DfaServices().get(session, CreativeFieldRemote.class);

    // Create creative field value structure.
    CreativeFieldValue creativeFieldValue = new CreativeFieldValue();
    creativeFieldValue.setId(-1);
    creativeFieldValue.setName(creativeFieldValueName);
    creativeFieldValue.setCreativeFieldId(creativeFieldId);

    // Create creative field value.
    CreativeFieldValueSaveResult creativeFieldValueSaveResult =
        service.saveCreativeFieldValue(creativeFieldValue);

    // Display creative field value ID.
    System.out.println("Creative field value with ID \"" + creativeFieldValueSaveResult.getId()
        +  "\" was created.");
  }
}
